package simpledb.tx.recovery;

import simpledb.log.LogMgr;
import simpledb.server.SimpleDB;

/**
 * The interface implemented by each type of log record.<br>
 * 由实现每种类型的日志记录的接口。
 * 
 * @author Edward Sciore
 */
public interface LogRecord {
  /**
   * The six different types of log record 六种不同类型的日志记录
   */
  static final int CHECKPOINT = 0, START = 1, COMMIT = 2, ROLLBACK = 3, SETINT = 4, SETSTRING = 5;

  static final LogMgr logMgr = SimpleDB.logMgr();

  /**
   * Writes the record to the log and returns its LSN. <br>
   * 将记录到日志中并返回它的LSN,其中SETINT和SETSTRING是真正向日志文件中写入查询操作等相关的数据，而CHECKPOINT，START，
   * COMMIT，ROLLBACK则是为数据库恢复，向日志文件中加入的辅助信息.
   * 
   * @return the LSN of the record in the log
   */
  int writeToLog();

  /**
   * Returns the log record's type. <br>
   * 返回日志记录的类型
   * 
   * @return the log record's type 日志的类型
   */
  int op();

  /**
   * Returns the transaction id stored with the log record. 返回与日志记录一起存储的事务id
   * 
   * @return the log record's transaction id 日志记录的事务id
   */
  int txNumber();

  /**
   * Undoes the operation encoded by this log record. The only log record types
   * for which this method does anything interesting are SETINT and SETSTRING.
   * <br>
   * 撤销此日志记录编码的操作。 该方法对其有意义的唯一日志记录类型是SETINT和SETSTRING。
   * 
   * @param txnum the id of the transaction that is performing the undo.
   *          执行撤销的事务的标识
   */
  void undo(int txnum);
}